﻿using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace GBricks
{
  [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Event", Justification = Justifications.HelperForEvent)]
  [SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = Justifications.HelperForEvent)]
  public static partial class Event
  {
    #region Methods

    [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Justification = Justifications.HelperForEvent)]
    public static bool Raise<TEventArgs>(this EventHandler<TEventArgs> handler, object sender, TEventArgs args) where TEventArgs : EventArgs {
      if(handler != null) {
        handler(sender, args);
        return true;
      }//if

      return false;
    }

    [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Justification = Justifications.HelperForEvent)]
    public static bool Raise<TEventArgs>(this EventHandler<TEventArgs> handler, object sender, Func<TEventArgs> args) where TEventArgs : EventArgs {
      Argument.NotNull(args, "args");

      if(handler != null) {
        var e = args();
        handler(sender, e);
        return true;
      }//if

      return false;
    }

    #endregion Methods
  }
}
